
Public Class EKGAbnormal

    Protected _ekg_abnormal_id As Integer
    Protected _ekg_abnormal_name_tha As String
    Protected _ekg_abnormal_name_eng As String
    Protected _Data As ArrayList
    Protected _DataCurrent As Integer

    Public Property ekg_abnormal_id() As Integer
        Get
            Return _ekg_abnormal_id
        End Get
        Set(ByVal value As Integer)
            _ekg_abnormal_id = value
        End Set
    End Property

    Public Property ekg_abnormal_name_tha() As String
        Get
            Return _ekg_abnormal_name_tha
        End Get
        Set(ByVal value As String)
            _ekg_abnormal_name_tha = value
        End Set
    End Property

    Public Property ekg_abnormal_name_eng() As String
        Get
            Return _ekg_abnormal_name_eng
        End Get
        Set(ByVal value As String)
            _ekg_abnormal_name_eng = value
        End Set
    End Property

    Public Function getEKGAbnormal() As DataSet
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_EKGAbnormal"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "EKGAbnormal")

        Return objDs
    End Function

    Protected Function getsEKGAbnormal() As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_EKGAbnormal"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "EKGAbnormal")

        For Each objDr As System.Data.DataRow In objDs.Tables("EKGAbnormal").Rows
            Dim obj As EKGAbnormal = New EKGAbnormal
            obj.ekg_abnormal_id = Utilities.ClearDBNullToMinValue(objDr.Item("ekg_abnormal_id"), TypeCode.Int32)
            obj.ekg_abnormal_name_tha = Utilities.ClearDBNullToEmptyString(objDr.Item("ekg_abnormal_name_tha"))
            obj.ekg_abnormal_name_eng = Utilities.ClearDBNullToEmptyString(objDr.Item("ekg_abnormal_name_eng"))
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Function getsEKGAbnormalByNameEng(ByVal inEKGAbnormalNameEng As String) As EKGAbnormal
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_EKGAbnormalByNameEng"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inEKGAbnormalNameEng", inEKGAbnormalNameEng)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "EKGAbnormal")

        Dim obj As EKGAbnormal = New EKGAbnormal

        For Each objDr As System.Data.DataRow In objDs.Tables("EKGAbnormal").Rows
            obj.ekg_abnormal_id = Utilities.ClearDBNullToMinValue(objDr.Item("ekg_abnormal_id"), TypeCode.Int32)
            obj.ekg_abnormal_name_tha = Utilities.ClearDBNullToEmptyString(objDr.Item("ekg_abnormal_name_tha"))
            obj.ekg_abnormal_name_eng = Utilities.ClearDBNullToEmptyString(objDr.Item("ekg_abnormal_name_eng"))
        Next

        Return obj
    End Function

    Public Function getMaxEKGAbnormalID() As Integer
        Dim outResult As Integer
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_MaxEKGAbnormalID"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "EKGAbnormal")

        outResult = IIf(objDs.Tables(0).Rows.Count <> 0, CInt(objDs.Tables(0).Rows(0).Item(0).ToString()) + 1, 1)

        Return outResult
    End Function

    Public Sub LoadEKGAbnormal()
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getsEKGAbnormal()
    End Sub

    Public Function NextRecord() As Boolean
        If ((Not _Data Is Nothing) AndAlso (((Not _Data Is Nothing) AndAlso _
            (_DataCurrent < _Data.Count And _Data.Count > 0)))) Then
            _ekg_abnormal_id = _Data(_DataCurrent).ekg_abnormal_id
            _ekg_abnormal_name_tha = _Data(_DataCurrent).ekg_abnormal_name_tha
            _ekg_abnormal_name_eng = _Data(_DataCurrent).ekg_abnormal_name_eng

            _DataCurrent += 1
            Return True
        End If
        Return False
    End Function

    Public Function insertEKGAbnormal(ByVal inEKGAbnormal As EKGAbnormal) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_EKGAbnormal"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inEKGAbnormalID", _
                Utilities.SendToDatabase(inEKGAbnormal.ekg_abnormal_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inEKGAbnormalNameTha", _
                Utilities.SendToDatabase(inEKGAbnormal.ekg_abnormal_name_tha))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inEKGAbnormalNameEng", _
                Utilities.SendToDatabase(inEKGAbnormal.ekg_abnormal_name_eng))
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function updateEKGAbnormal(ByVal inEKGAbnormal As EKGAbnormal) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_UPDATE_EKGAbnormal"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inEKGAbnormalID", _
                Utilities.SendToDatabase(inEKGAbnormal.ekg_abnormal_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inEKGAbnormalNameTha", _
                Utilities.SendToDatabase(inEKGAbnormal.ekg_abnormal_name_tha))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inEKGAbnormalNameEng", _
                Utilities.SendToDatabase(inEKGAbnormal.ekg_abnormal_name_eng))
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function deleteEKGAbnormal(ByVal inEKGAbnormal As EKGAbnormal) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_DELETE_EKGAbnormal"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inEKGAbnormalID", _
                Utilities.SendToDatabase(inEKGAbnormal.ekg_abnormal_id))
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

End Class
